package com.qch.thread;

import com.qch.bean.ConsumerComponet;

import java.util.concurrent.ThreadLocalRandom;
import java.util.concurrent.TimeUnit;

/**
 * @Author qch
 * @Date 2021/2/20
 */
public class ConsumerThread implements Runnable {
    private ConsumerComponet service;
    private String method;
    private String message;
    private int timeout;
    public ConsumerThread(ConsumerComponet componet, String method,String message,int timeout) {
        this.service = componet;
        this.method = method;
        this.message = message;
        this.timeout = timeout;
    }

    @Override
    public void run() {
        final int i = ThreadLocalRandom.current().nextInt(3);
        switch (i) {
            case 0:
                service.methodA("A", ThreadLocalRandom.current().nextInt(100));
                break;
            case 1:
                service.methodB("B", ThreadLocalRandom.current().nextInt(100));
                break;
            case 2:
                service.methodC("C", ThreadLocalRandom.current().nextInt(100));
                break;
            default:
                break;
        }
       /* for (int i = 0; i <2000 ; i++) {
            try {
                Thread.sleep(5);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            service.methodA(message, timeout);
            try {
                Thread.sleep(5);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            service.methodB(message, timeout);
            try {
                Thread.sleep(5);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            service.methodC(message, timeout);

        }*/
        /*if(method == "A") {
            String s = service.methodA(message,timeout);
        } else if(method == "B") {
            service.methodB(message,timeout);
        } else if(method == "C") {
            service.methodCmessage,timeout);
        }*/
    }

    private void call(){
        if(method.equals( "A")) {
            String s = service.methodA(message,timeout);
        } else if(method .equals("B")) {
            service.methodB(message,timeout);
        } else if(method .equals( "C")) {
            service.methodC(message,timeout);
        }
    }
}
